//package com.example.demo.config.websocket.server;
//
//import com.alibaba.fastjson.JSON;
//import com.example.demo.config.websocket.util.SpringUtil;
//import com.example.demo.outstyle.EchartData;
//import com.example.demo.outstyle.Message;
//import com.example.demo.service.PositionService;
//import com.example.demo.service.serviceImp.PositionServiceImp;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import javax.websocket.*;
//import javax.websocket.server.PathParam;
//import javax.websocket.server.ServerEndpoint;
//import java.io.IOException;
//import java.util.List;
//import java.util.concurrent.CopyOnWriteArraySet;
//
//@Component
//@ServerEndpoint("/websocket")
//public class WebSocketServer {
//
//    private static PositionService positionServiceImp = SpringUtil.getBean(PositionServiceImp.class);
//    static Logger log = LoggerFactory.getLogger(WebSocketServer.class);
//    private static CopyOnWriteArraySet<WebSocketServer> webSocketServers = new CopyOnWriteArraySet<>();
//    private static int onLineCount = 0;
//
//    private Session session;
//    @OnOpen
//    public void onOpen(Session session) {
//        this.session = session;
//        webSocketServers.add(this);
//        addOnlineCount();
//        log.info("有新用户进行连接，当前连接数为: " + getOnLineCount());
//        try {
//            sendMessage("连接成功");
//        } catch (Exception e) {
//            log.error("websocket打开连接时: " + e.getMessage());
//        }
//    }
//
//    @OnMessage
//    public void onMessage(String messages, Session session) throws Exception{
//        Message message = new Message();
//        message.setMsg("查询成功");
//        message.setState(0);
//
//        EchartData echartData = new EchartData();
//        echartData.setBase(positionServiceImp.selectBaseData());
//        echartData.setCompanyBySize(positionServiceImp.selectCompanyBySize());
//        echartData.setCompanyLogo(positionServiceImp.selectCompanyLogo());
//        echartData.setAdvantageWords(positionServiceImp.selectComponyWelfare());
//        echartData.setLanguageCounts(positionServiceImp.selectLanguageCounts());
//        echartData.setPositionByCity(positionServiceImp.selectPositionByCity());
//        echartData.setPositionByEducation(positionServiceImp.selectPositionByEducation());
//        echartData.setPositionBySalary(positionServiceImp.selectPositionBySalary());
//        echartData.setSalaryByWorkYear(positionServiceImp.selectSalaryByWorkYear());
//        echartData.setPositionByLanguage(positionServiceImp.selectPositionByLanguage());
//        echartData.setTop5ByDistrict(positionServiceImp.selectTop5ByDistrict());
//        message.setData(echartData);
//        session.getBasicRemote().sendText(JSON.toJSONString(message));
//    }
//
//    public void sendMessage(String message) throws IOException {
//        this.session.getBasicRemote().sendText(message);
//    }
//
//    public static synchronized void addOnlineCount() {
//        WebSocketServer.onLineCount++;
//    }
//    public static synchronized int getOnLineCount() {
//        return onLineCount;
//    }
//
//    @OnError
//    public void onError(Session session, Throwable throwable) {
//        System.out.println("发生错误");
//    }
//
//}
